package cn.rcth.base.serivce.impl;

import cn.rcth.base.domain.Delivery;
import cn.rcth.base.domain.DeliveryMapping;
import cn.rcth.base.domain.Order;
import cn.rcth.base.mapper.DeliveryMapper;
import cn.rcth.base.mapper.DeliveryMappingMapper;
import cn.rcth.base.mapper.OrderMapper;
import cn.rcth.base.serivce.IDeliverySerivce;
import cn.rcth.base.util.ExpressUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Transactional
public class DeliverySerivceImpl implements IDeliverySerivce {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private DeliveryMapper deliveryMapper;

    @Autowired
    private DeliveryMappingMapper deliveryMappingMapper;

    @Override
    public String deliverySelect(Long orderId) {

        Order order = orderMapper.selectByPrimaryKey(orderId);
        Delivery delivery = deliveryMapper.selectDeliveryByOrderId(order.getId());
        String deliveryCompany = delivery.getDeliveryCompany();
        DeliveryMapping deliveryMapping = deliveryMappingMapper.selecyDeliverByCompany(deliveryCompany);
        String wuliu = ExpressUtils.getWuliu( deliveryMapping.getDeliveryType(),delivery.getDeliveryNumber());
        return wuliu;
    }

    @Override
    public Delivery getDelivery(Long orderId) {
        Delivery delivery = deliveryMapper.selectDeliveryByOrderId(orderId);
        return delivery;
    }
}
